/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package backend;

import db.MovieDAO;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.ArrayList;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

@ManagedBean(name = "MovieBean")
@RequestScoped
public class MovieBean {

    public int id;
    public String name;
    public String type;
    public double rating;
    public double distrFee;
    public int numCopies;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public double getRating() {
        return rating;
    }

    public void setRating(double rating) {
        this.rating = rating;
    }

    public double getDistrFee() {
        return distrFee;
    }

    public void setDistrFee(double distrFee) {
        this.distrFee = distrFee;
    }

    public int getNumCopies() {
        return numCopies;
    }

    public void setNumCopies(int numCopies) {
        this.numCopies = numCopies;
    }
    

    public MovieBean() {
    }

    public void createMovie() throws Exception{
        MovieDAO movie = MovieDAO.createMovie(name, type, rating, distrFee, numCopies);
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (movie != null) {
            facesContext.addMessage("loginForm", new FacesMessage("Registed"));
        }
        else{
            facesContext.addMessage("loginForm", new FacesMessage("Hourly Rate should be numeric format."));
            facesContext.addMessage("loginForm", new FacesMessage("SSN should be 9 digit."));
            facesContext.addMessage("loginForm", new FacesMessage("Start Date should be yyyy-mm-dd format."));
        }
        
    }

}
